package com.jinlejia.erp.ui.new_house.adapter;

import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.freedom.yefeng.yfrecyclerview.YfListAdapter;
import com.freedom.yefeng.yfrecyclerview.YfSimpleViewHolder;
import com.jinlejia.erp.R;
import com.jinlejia.erp.utils.DateUtil;
import com.jinlejia.erp.utils.RecommendState;

import java.util.ArrayList;
import java.util.Map;

/**
 * 申请Adapter
 */
public class ApplyAdapter extends YfListAdapter<Map<String, String>> {

    public ApplyAdapter(ArrayList<Map<String, String>> data) {
        super(data);
    }

    @Override
    public RecyclerView.ViewHolder onCreateDataViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_apply_layout, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public RecyclerView.ViewHolder onCreateEmptyViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.empty_layout, parent, false);
        TextView txt = (TextView) view.findViewById(R.id.id_tips);
        txt.setText("您还没有申请过哦～");
        ImageView img = (ImageView) view.findViewById(R.id.id_placeholder);
        img.setImageResource(R.mipmap.ic_no_apply);
        return new YfSimpleViewHolder(view);
    }
    @Override
    public RecyclerView.ViewHolder onCreateErrorViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.error_layout, parent, false);
        return new YfSimpleViewHolder(view);
    }
    @Override
    public void onBindDataViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        ((ViewHolder) viewHolder).name.setText(mData.get(i).get("customerName"));
        ((ViewHolder) viewHolder).phone.setText(mData.get(i).get("customerTel"));
        ((ViewHolder) viewHolder).house.setText(mData.get(i).get("houseName"));
        ((ViewHolder) viewHolder).state.setText(RecommendState.getStateStr(mData.get(i).get("state")));
        ((ViewHolder) viewHolder).applyType.setText(RecommendState.getStateType(mData.get(i).get("state")));
        ((ViewHolder) viewHolder).time.setText(DateUtil.getTime(mData.get(i).get("createTime"), "yyyy-MM-dd")) ;
        viewHolder.itemView.setTag(mData.get(i));
    }

    @Override
    public RecyclerView.ViewHolder onCreateLoadingViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.loading_layout, parent, false);
        return new YfSimpleViewHolder(view);
    }

    @Override
    public RecyclerView.ViewHolder onCreateFooterViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.footer_loading, parent, false);
        return new YfSimpleViewHolder(view);
    }

    private static final class ViewHolder extends RecyclerView.ViewHolder {

        TextView time;
        TextView state;
        TextView name;
        TextView phone;
        TextView house;
        TextView applyType;

        public ViewHolder(View itemView) {
            super(itemView);
            time = (TextView) itemView.findViewById(R.id.id_time);
            state = (TextView) itemView.findViewById(R.id.id_state);
            name = (TextView) itemView.findViewById(R.id.id_name);
            phone = (TextView) itemView.findViewById(R.id.id_phone);
            house = (TextView) itemView.findViewById(R.id.id_houses);
            applyType = (TextView) itemView.findViewById(R.id.id_apply_type);
        }
    }

}
